#pragma once

#include <string>
#include <fstream>
#include "utf8.h"

#define utf8char(C) utf8::internal::mask8((C))

class utf8string
{
public:
	//class utf8char
	//{
	//public:
	//	utf8char(const std::string & source, std::size_t position, std::size_t length)
	//		: _source(source), _position(position), _length(length)
	//	{
	//	}

	//private:
	//	const std::string & _source;
	//	const std::size_t _position;
	//	const std::size_t _length;
	//};

	//class iterator
	//{
	//	friend class utf8string;
	//public:
	//	utf8char operator * ()
	//	{
	//	}

	//private:
	//	iterator(std::string::iterator it)
	//		: _internal(it)
	//	{
	//	}

	//	std::string::iterator _internal;
	//};

	typedef utf8::iterator<std::string::iterator> iterator;
	typedef utf8::iterator<std::string::const_iterator> const_iterator;

	utf8string() {}
	utf8string(const std::string & source)
	{
	}

	void readform(const char * filename)
	{
		std::ifstream fin(filename);
		std::istreambuf_iterator<char> beg(fin), end;
		bool start_with_bom = utf8::skip_bom_if_exists(beg, end);
		_source = std::string(beg, end);

		iterator it(_source.begin(), _source.begin(), _source.end());
	}

	iterator begin()
	{
		return iterator(_source.begin(), _source.begin(), _source.end());
	}

	const_iterator begin() const
	{
		return const_iterator(_source.begin(), _source.begin(), _source.end());
	}

	const_iterator end() const
	{
		return const_iterator(_source.end(), _source.begin(), _source.end());
	}

	static bool isalphabet(char c)
	{
		return (c>='a' && c <='z') || (c>='A' && c<='Z');
	}

	//static bool isalphabet(utf8::uint32_t u8char)
	//{
	//	const utf8::uint32_t a = utf8char('a');
	//	const utf8::uint32_t z = utf8char('z');
	//	const utf8::uint32_t A = utf8char('A');
	//	const utf8::uint32_t Z = utf8char('Z');

	//	return (u8char>=a && u8char <=z) || (u8char>=A && u8char<=Z);
	//}

	static bool isdigital(char c)
	{
		return (c>='0' && c <='9');
	}

	//static bool isnumber(utf8::uint32_t u8char)
	//{
	//	const utf8::uint32_t zero = utf8char('0');
	//	const utf8::uint32_t nine = utf8char('9');

	//	return (u8char>=zero && u8char <=nine);
	//}

	static bool iswhite(char c)
	{
		return c == ' '
			|| c == '\t'
			|| c == '\n'
			|| c == '\r';
	}

	static bool iswhite(utf8::uint32_t u8char)
	{
		return u8char == utf8char(' ')
			|| u8char == utf8char('\t')
			|| u8char == utf8char('\n')
			|| u8char == utf8char('\r');
	}

	std::string & getsource()
	{
		return _source;
	}

private:
	std::string _source;
};